package com.wxproject.demo.Controller.Admin;

import com.wxproject.demo.Common.lang.ResultBody;
import com.wxproject.demo.Entity.VO.CarouselImgVO;
import com.wxproject.demo.Service.UserFileService;
import com.wxproject.demo.Utils.UploadUtil;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author zqf
 * @date 2021/4/16 23:36
 * @description
 */
@RestController
@RequestMapping("/admin")
public class AdminCarouselController {
    @Autowired
    private UserFileService userFileService;
    //获得轮播图
    @GetMapping("/getCarouselImg")
    public ResultBody getCarouselImg(){
        return ResultBody.ok().data("CarouseImg",userFileService.getAdminCarouselImg());
    }

    //管理员上传轮播图
    @PostMapping("/uploadCarouselImg")
    @RequiresRoles(logical = Logical.OR, value = {"admin"})
    public ResultBody uploadCarouselImg(@RequestParam("file") MultipartFile file) throws IOException {
        return UploadUtil.uploadFile(file);
    }

    //删除轮播图
    @PostMapping("/delCarouselImg/{id}")
    @RequiresRoles(logical = Logical.OR, value = {"admin"})
    public ResultBody delCarouselImg(@PathVariable("id")String id){
        userFileService.delCarouselImg(id);
        return ResultBody.ok().message("删除成功");
    }
}
